﻿CREATE TABLE [dbo].[Query]
(
	[QueryId] INT NOT NULL PRIMARY KEY IDENTITY, 
	[RuleId] INT NOT NULL,
    [LanguageId] SMALLINT NOT NULL, 
    [StatementTypeId] SMALLINT NOT NULL, 
    [ColumnCompareModeId] SMALLINT NOT NULL, 
    [TemplateId] INT NULL, 
	[QueryName] NVARCHAR(100) NOT NULL, 
	[IsDefault] BIT NOT NULL DEFAULT 0,
	[UseTempTableForSource] bit NOT NULL DEFAULT 1,
    [QueryText] NVARCHAR(MAX) NULL, 
    CONSTRAINT [FK_Query_Rule] FOREIGN KEY ([RuleId]) REFERENCES [dbo].[Rule]([RuleId]), 
    CONSTRAINT [FK_Query_Language] FOREIGN KEY ([LanguageId]) REFERENCES [dbo].[Language]([LanguageId]), 
    CONSTRAINT [FK_Query_StatementType] FOREIGN KEY ([StatementTypeId]) REFERENCES [dbo].[StatementType]([StatementTypeId]), 
    CONSTRAINT [FK_Query_EqualityComparisonMode] FOREIGN KEY ([ColumnCompareModeId]) REFERENCES [dbo].[ColumnCompareMode]([ColumnCompareModeId]), 
    CONSTRAINT [FK_Query_Template] FOREIGN KEY ([TemplateId]) REFERENCES [dbo].[Template]([TemplateId])
)
